/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * LobbySelectionMenu.java
 *
 * Created on Feb 22, 2012, 4:02:18 PM
 */
package gui;

import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

/**
 *
 * @author dalby
 */
public class LobbySelectionMenu extends javax.swing.JPanel {
	
	int seconds =30;
	int screenSize = 2;
    BufferedImage image;   // holds image for panel background
    int w, h;              // holds dimensions for panel

    /** Creates new form LobbySelectionMenu */
    public LobbySelectionMenu(int screenSize) {
    	this.screenSize = screenSize;
   	 // read the image file and set the custom panel dimensions based on
       // image dimensions.
       try {
       	if (screenSize == 1)
       		image = ImageIO.read(new File("black_chips800X600.JPG"));  // holds smaller image
       	else if (screenSize == 2)
       		image = ImageIO.read(new File("black_chips2.JPG"));  // holds larger image
           w = image.getWidth();                         // holds image width
           h = image.getHeight();                        // holds image height
           // throw exception and exit if file problems
       } catch (IOException ioe) {
           System.out.println(ioe);
           System.exit(0);
       }

       initComponents();
       
   }
   
// Generic method to get preferred size
   public Dimension getPreferredSize() {
       return new Dimension(w, h);
   }

   // override of paintComponent to use image
   public void paintComponent(Graphics g) {
       super.paintComponent(g);

       g.drawImage(image, 0, 0, this);
   }


    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        lobbyScrollPanel = new javax.swing.JScrollPane();
        leaveButton = new javax.swing.JButton();
        joinButton = new javax.swing.JButton();
        createGameButton = new javax.swing.JButton();
        
        lobbyScrollPanel.setOpaque(false);
        lobbyScrollPanel.getViewport().setOpaque(false);


        leaveButton.setText("LEAVE");
        leaveButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                leaveButtonActionPerformed(evt);
            }
        });

        joinButton.setText("JOIN");
        joinButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                joinButtonActionPerformed(evt);
            }
        });

        createGameButton.setText("Create New Game");
        createGameButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                createGameButtonActionPerformed(evt);
            }
        });

        if (screenSize == 1){
        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(lobbyScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addComponent(createGameButton, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                        .addComponent(joinButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(leaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(lobbyScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 305, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(218, 218, 218)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(leaveButton)
                    .addComponent(joinButton)
                    .addComponent(createGameButton))
                .addContainerGap(12, Short.MAX_VALUE))
        );
        }
        else if (screenSize == 2){
        	  javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
              this.setLayout(layout);
              layout.setHorizontalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                          .addComponent(lobbyScrollPanel, javax.swing.GroupLayout.DEFAULT_SIZE, 571, Short.MAX_VALUE)
                          .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                              .addComponent(createGameButton, javax.swing.GroupLayout.PREFERRED_SIZE, 186, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 176, Short.MAX_VALUE)
                              .addComponent(joinButton, javax.swing.GroupLayout.PREFERRED_SIZE, 105, javax.swing.GroupLayout.PREFERRED_SIZE)
                              .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                              .addComponent(leaveButton, javax.swing.GroupLayout.PREFERRED_SIZE, 98, javax.swing.GroupLayout.PREFERRED_SIZE)))
                      .addContainerGap())
              );
              layout.setVerticalGroup(
                  layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                  .addGroup(layout.createSequentialGroup()
                      .addContainerGap()
                      .addComponent(lobbyScrollPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 805, javax.swing.GroupLayout.PREFERRED_SIZE)
                      .addGap(18, 18, 18)
                      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                          .addComponent(leaveButton)
                          .addComponent(joinButton)
                          .addComponent(createGameButton))
                      .addContainerGap(12, Short.MAX_VALUE))
              );
        }

    }// </editor-fold>//GEN-END:initComponents

    private void createGameButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createGameButtonActionPerformed
        // TODO add your handling code here:
        MenuCycling.displayLobbyScreen();
       
    }//GEN-LAST:event_createGameButtonActionPerformed
    
    private void joinButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_createGameButtonActionPerformed
        // TODO add your handling code here:
        MenuCycling.displayJoinLobbyScreen();
       
    }//GEN-LAST:event_createGameButtonActionPerformed

    private void leaveButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_leaveButtonActionPerformed
        // TODO add your handling code here:
        MenuCycling.displayStartScreen();
    }
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton createGameButton;
    private javax.swing.JButton joinButton;
    private javax.swing.JButton leaveButton;
    private javax.swing.JScrollPane lobbyScrollPanel;
    // End of variables declaration//GEN-END:variables
}
